var fs = require('fs-extra');
var path = require('path');

function Copy(options) {
  if (!Array.isArray(options)) {
    options = [options];
  }

  this.options = options;
}

Copy.prototype.apply = function (compiler) {
  var self = this;
  var chalk = require('chalk');

  compiler.hooks.done.tap('copy', function (compilation) {
    console.log(chalk.yellow('  Copy start....'));

    self.options.forEach(function (option) {
      function copyStart() {
        console.log(path.resolve(process.cwd(), option.from),path.resolve(process.cwd(), option.to), 'jjjj');
        fs.copy(
          path.resolve(process.cwd(), option.from),
          path.resolve(process.cwd(), option.to),
        )
          .then(function () {
            console.log(
              chalk.blue(
                '    ' + option.from + ' => ' + option.to + ' Complete!'
              )
            );
          })
          .catch(function () {
            console.log(
              chalk.red('    ' + option.from + ' => ' + option.to + ' Failure!')
            );
          });
      }

      copyStart();
    });
  });
};

module.exports = Copy;
